﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Cisoft.YiWu.Model;
using Cisoft.YiWu.BLL;
using Cisoft.IntegrationSystem.Model;
using Cisoft.IntegrationSystem.BLL;

public partial class yiwutong_web_DepartmentShow : WebUI.Page.BasePage
{
    public string rehospitalid = "";
    public string redepartmentid = "";
    public string iconUrl = "../images/images_20100205/icon_title1.gif";
    public string titleclas = "";

    private DepartmentInfoMO amo = new DepartmentInfoMO();
    private DepartmentInfoBO abo = new DepartmentInfoBO();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["hospitalid"] != null && Request.QueryString["hospitalid"] != "" && Request.QueryString["departmentid"] != null && Request.QueryString["departmentid"] != "")
            {
                rehospitalid = Request.QueryString["hospitalid"].ToString().Replace("'", "");
                redepartmentid = Request.QueryString["departmentid"].ToString().Replace("'", "");
                lblHospitalID.Text = Request.QueryString["hospitalid"].ToString().Replace("'", "");
                lblDepartmentID.Text = Request.QueryString["departmentid"].ToString().Replace("'", "");
                //lblHospitalName.Text = GetHospitalName(Request.QueryString["hospitalid"].ToString());

                //数据初始化
                BindData();
            }
            else
            {
                Response.Redirect("index.aspx");
            }
        }
    }
    #region 绑定数据
    private void BindData()
    {
        int id = GetDepartmentQueryString();
        if (id > 0)
        {
            DataSet dsall = new DataSet();
            dsall = abo.GetModelAllInfo(id);

            amo = abo.GetModel(id);

            if (amo != null && dsall.Tables[0].Rows.Count>0)
            {
                lblHospitalName.Text = dsall.Tables[0].Rows[0]["HI_HospitalName"].ToString();
                lblHospitalNamebig.Text = dsall.Tables[0].Rows[0]["HI_HospitalName"].ToString();

                lblDepartmentName.Text = amo.DI_DepartmentlName;
                lblDepartmentNamebig.Text = amo.DI_DepartmentlName;

                //新逻辑，取出的二进制字符串数据转换为真正显示的字符串  20081024---gwh---
                string strmiddlestring = amo.DI_DepartmentSummary.ToString();

                if (strmiddlestring != "")
                {
                    byte[] dd = Convert.FromBase64String(strmiddlestring); // <-- 将数据从数据库中取出 
                    lblshow.Text = System.Text.Encoding.UTF8.GetString(dd);
                }

                //如果存在医生则进行
                DoctorInfoBO bllDoctor = new DoctorInfoBO();

                DataSet ds = bllDoctor.GetList(" DT_DoctorDepartmentID=" + lblDepartmentID.Text);

                if (ds.Tables[0].Rows.Count > 0)
                {
                    BindData3(ds);
                }
                else
                {
                    PostList.Text = "暂未存在相应医生信息";
                }
                //PostList.InnerHtml = ShowHtmlforEnterpriseList();
            }
            else
            {
                PageError("不存在该科室！", "index.aspx", "点击返回重试", "");
            }
        }
        else
        {
            PageError("不存在该科室！", "index.aspx", "点击返回重试", "");
        }
    }
    #endregion

    #region 获取传入医院的编号
    private int GetHospitalQueryString()
    {
        int id = 0;
        if (string.IsNullOrEmpty(Request.QueryString["hospitalid"].ToString().Replace("'","")))
        {
            PageError("不存在该医院！", "index.aspx", "点击返回重试", "");
        }
        else
        {
            try
            {
                id = int.Parse(Request.QueryString["hospitalid"].ToString().Replace("'",""));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        return id;
    }
    #endregion

    #region 获取传入的编号
    private int GetDepartmentQueryString()
    {
        int id = 0;
        if (string.IsNullOrEmpty(Request.QueryString["departmentid"].ToString().Replace("'","")))
        {
            PageError("不存在该科室！", "index.aspx", "点击返回重试", "");
        }
        else
        {
            try
            {
                id = int.Parse(Request.QueryString["departmentid"].ToString().Replace("'",""));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        return id;
    }
    #endregion

    #region 全为数字
    public bool isnumber(string s)
    {
        int Flag = 0;
        char[] str = s.ToCharArray();
        for (int i = 0; i < str.Length; i++)
        {
            if (Char.IsNumber(str[i]))
            {
                Flag++;
            }
            else
            {
                Flag = -1;
                break;
            }
        }
        if (Flag > 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    #endregion

    private void BindData3(DataSet myDs)
    {
        dataList1.RepeatColumns = 4;
        dataList1.DataSource = myDs.Tables[0].DefaultView;
        dataList1.ItemDataBound += new DataListItemEventHandler(dataList1_ItemDataBound);
        dataList1.DataBind();
    }

    private void dataList1_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
        {
            // 
            Literal litImg = (Literal)e.Item.FindControl("litIconImg3");

            if (iconUrl != "")
                litImg.Text = "<img src='" + iconUrl + "'>";
            else
                litImg.Text = "";

            // 显示栏目图片
            //if (isShowColImg)
            //{
            //    Image colImg = (Image)e.Item.FindControl("ColImg3");
            //    if (DataBinder.Eval(e.Item.DataItem, "ColumnImg").ToString() != "")
            //    {
            //        colImg.ImageUrl = DataBinder.Eval(e.Item.DataItem, "ColumnImg").ToString();
            //    }
            //    else
            //        colImg.Visible = false;
            //}

            // titleclas
            HyperLink linkCol = (HyperLink)e.Item.FindControl("ColumnLink3");

            linkCol.Text = DataBinder.Eval(e.Item.DataItem, "DT_DoctorName").ToString();
            linkCol.ToolTip = "点击查看详细 " + DataBinder.Eval(e.Item.DataItem, "DT_DoctorName").ToString();

            //if (DataBinder.Eval(e.Item.DataItem, "OutUrl").ToString() != "")
            //{
            //    linkCol.NavigateUrl = DataBinder.Eval(e.Item.DataItem, "OutUrl").ToString();
            //    linkCol.Target = "_blank";
            //}
            //else
            //{
            linkCol.NavigateUrl = "DoctorShow.aspx?hospitalid=" + lblHospitalID.Text + "&departmentid=" + lblDepartmentID.Text + "&doctorid=" + DataBinder.Eval(e.Item.DataItem, "DT_DoctorID").ToString();
            linkCol.Target = "_blank";
            //}

            //linkCol.CssClass = titleclas;
        }
    }
}
